/*** Eclipse Class Decompiler plugin, copyright (c) 2012 Chao Chen (cnfree2000@hotmail.com) ***/
package com.qihoo.gamecenter.sdk.common.i;

import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiManager;
import android.os.Build;
import android.os.Build.VERSION;
import android.provider.Settings.System;
import android.telephony.TelephonyManager;

public class d {
    public static boolean a(Context paramContext, boolean paramBoolean) {
        boolean bool = a(paramContext);
        if (bool == (!(paramBoolean))) {
            WifiManager localWifiManager = (WifiManager) paramContext.getSystemService("wifi");
            localWifiManager.setWifiEnabled(paramBoolean);
        }
        return bool;
    }

    public static boolean a(Context paramContext) {
        WifiManager localWifiManager = (WifiManager) paramContext.getSystemService("wifi");
        return localWifiManager.isWifiEnabled();
    }

    public static boolean b(Context paramContext, boolean paramBoolean) {
        int i = 1;
        try {
            c(paramContext, paramBoolean);
            i = 0;
        } catch (Exception localException) {
            c.a("ConnectionTools", new Object[] { "setGPRSEnabled Exception", localException.toString() });
        } finally {
            if (i != 0)
                e(paramContext);
        }
        return i;
    }

    public static boolean b(Context paramContext) {
        try {
            return f(paramContext);
        } catch (Exception localException) {
            c.a("ConnectionTools", new Object[] { "isGPRSEnabled Exception", localException.toString() });
        }
        return false;
    }

    public static boolean c(Context paramContext) {
        String str = Settings.System.getString(paramContext.getContentResolver(), "airplane_mode_on");
        return str.equals("1");
    }

    private static void e(Context paramContext) {
        String[] arrayOfString = new String[2];
        String str1 = Build.MODEL;
        String str2 = Build.MANUFACTURER;
        if ((str1.equalsIgnoreCase("ME525")) || (str1.equalsIgnoreCase("MB525"))) {
            arrayOfString[0] = "com.motorola.blur.datamanager.app";
            arrayOfString[1] = "com.motorola.blur.datamanager.app.DataManagerAppPreferenceActivity";
        }
        else if (str2.equalsIgnoreCase("HTC")) {
            arrayOfString[0] = "com.android.settings";
            arrayOfString[1] = "com.android.settings.WirelessSettings";
        }
        else {
            arrayOfString[0] = "com.android.phone";
            arrayOfString[1] = "com.android.phone.Settings";
        }
        try {
            Intent localIntent = new Intent("android.intent.action.VIEW");
            localIntent.setClassName(arrayOfString[0], arrayOfString[1]);
            if (paramContext != null)
                paramContext.startActivity(localIntent);
        } catch (ActivityNotFoundException localActivityNotFoundException) {
            c.b("ConnectionTools", new Object[] { localActivityNotFoundException.toString() });
        }
    }

    private static void c(Context paramContext, boolean paramBoolean) {
        ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext
                .getSystemService("connectivity");
        if (a(localConnectivityManager) == paramBoolean)
            return;
        Object localObject1;
        Object localObject2;
        if (Build.VERSION.SDK_INT > 8) {
            localObject1 = new Class[] { Boolean.TYPE };
            localObject2 = new Object[] { Boolean.valueOf(paramBoolean) };
            l.a(localConnectivityManager, "setMobileDataEnabled", localObject1, localObject2);
        }
        else {
            localObject1 = g(paramContext);
            if (localObject1 == null)
                return;
            localObject2 = new Class[] { String.class };
            Object[] arrayOfObject = { "default" };
            if (paramBoolean) {
                l.a(localObject1, "disableApnType", localObject2, arrayOfObject);
                l.a(localObject1, "disableDataConnectivity", new Class[0], new Object[0]);
            }
            else {
                l.a(localObject1, "enableApnType", localObject2, arrayOfObject);
                l.a(localObject1, "enableDataConnectivity", new Class[0], new Object[0]);
            }
        }
    }

    private static boolean f(Context paramContext) {
        ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext
                .getSystemService("connectivity");
        return a(localConnectivityManager);
    }

    private static boolean a(ConnectivityManager paramConnectivityManager) {
        Boolean localBoolean = (Boolean) l.a(paramConnectivityManager, "getMobileDataEnabled", new Class[0],
                new Object[0]);
        return ((localBoolean != null) && (localBoolean.booleanValue()));
    }

    private static Object g(Context paramContext) {
        TelephonyManager localTelephonyManager = (TelephonyManager) paramContext.getSystemService("phone");
        return l.a(localTelephonyManager, "getITelephony", null, null);
    }

    public static boolean d(Context paramContext) {
        try {
            ConnectivityManager localConnectivityManager = (ConnectivityManager) paramContext
                    .getSystemService("connectivity");
            if (localConnectivityManager == null)
                return false;
            NetworkInfo[] arrayOfNetworkInfo1 = localConnectivityManager.getAllNetworkInfo();
            if (arrayOfNetworkInfo1 == null)
                return false;
            for (NetworkInfo localNetworkInfo : arrayOfNetworkInfo1)
                if (localNetworkInfo.isConnectedOrConnecting())
                    return true;
            return false;
        } catch (Throwable localThrowable) {}
        return false;
    }
}